home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / testpage.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  4KB  |  128 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __version__ = '6.0'
  5. __title__ = 'Testpage Print Utility'
  6. __mod__ = 'hp-testpage'
  7. __doc__ = "Print a tespage to a printer. Prints a summary of device information and shows the printer's margins."
  8. import sys
  9. import os
  10. import getopt
  11. import re
  12. import time
  13. from base.g import *
  14. from base import device, utils, tui, module
  15. from prnt import cups
  16.  
  17. try:
  18.     mod = module.Module(__mod__, __title__, __version__, __doc__, None, (INTERACTIVE_MODE, GUI_MODE), (UI_TOOLKIT_QT4,))
  19.     mod.setUsage(module.USAGE_FLAG_DEVICE_ARGS)
  20.     (opts, device_uri, printer_name, mode, ui_toolkit, loc) = mod.parseStdOpts()
  21.     (printer_name, device_uri) = mod.getPrinterName(printer_name, device_uri)
  22.     wait_for_printout = False
  23.     if mode == GUI_MODE:
  24.         if not utils.canEnterGUIMode4():
  25.             log.error('%s -u/--gui requires Qt4 GUI support. Entering interactive mode.' % __mod__)
  26.             mode = INTERACTIVE_MODE
  27.         
  28.     
  29.     if mode == GUI_MODE:
  30.         
  31.         try:
  32.             from PyQt4.QtGui import QApplication
  33.             from ui4.printtestpagedialog import PrintTestPageDialog
  34.         except ImportError:
  35.             log.error('Unable to load Qt4 support. Is it installed?')
  36.             sys.exit(1)
  37.  
  38.         log.set_module('%s(UI)' % __mod__)
  39.         app = QApplication(sys.argv)
  40.         dialog = PrintTestPageDialog(None, printer_name)
  41.         dialog.show()
  42.         
  43.         try:
  44.             log.debug('Starting GUI loop...')
  45.             app.exec_()
  46.         except KeyboardInterrupt:
  47.             sys.exit(0)
  48.  
  49.         sys.exit(0)
  50.     
  51.     if mode == INTERACTIVE_MODE:
  52.         
  53.         try:
  54.             d = device.Device(device_uri, printer_name)
  55.         except Error:
  56.             e = None
  57.             log.error('Device error (%s).' % e.msg)
  58.             sys.exit(1)
  59.  
  60.         
  61.         try:
  62.             d.open()
  63.         except Error:
  64.             log.error('Unable to print to printer. Please check device and try again.')
  65.             sys.exit(1)
  66.         
  67.  
  68.         wait_for_printout = False
  69.         if d.isIdleAndNoError():
  70.             d.close()
  71.             log.info('Printing test page to printer %s...' % printer_name)
  72.             
  73.             try:
  74.                 d.printTestPage(printer_name)
  75.             except Error:
  76.                 e = None
  77.                 if e.opt == ERROR_NO_CUPS_QUEUE_FOUND_FOR_DEVICE:
  78.                     log.error('No CUPS queue found for device. Please install the printer in CUPS and try again.')
  79.                 else:
  80.                     log.error('An error occured (code=%d).' % e.opt)
  81.             except:
  82.                 e.opt == ERROR_NO_CUPS_QUEUE_FOUND_FOR_DEVICE
  83.  
  84.             if wait_for_printout:
  85.                 log.info('Test page has been sent to printer. Waiting for printout to complete...')
  86.                 time.sleep(5)
  87.                 i = 0
  88.                 while True:
  89.                     time.sleep(5)
  90.                     
  91.                     try:
  92.                         d.queryDevice(quick = True)
  93.                     except Error:
  94.                         e = None
  95.                         log.error('An error has occured.')
  96.  
  97.                     if d.error_state == ERROR_STATE_CLEAR:
  98.                         break
  99.                     elif d.error_state == ERROR_STATE_ERROR:
  100.                         cleanup_spinner()
  101.                         log.error('An error has occured (code=%d). Please check the printer and try again.' % d.status_code)
  102.                         break
  103.                     elif d.error_state == ERROR_STATE_WARNING:
  104.                         cleanup_spinner()
  105.                         log.warning('There is a problem with the printer (code=%d). Please check the printer.' % d.status_code)
  106.                     else:
  107.                         update_spinner()
  108.                     i += 1
  109.                     if i > 24:
  110.                         break
  111.                         continue
  112.                 cleanup_spinner()
  113.             else:
  114.                 log.info('Test page has been sent to printer.')
  115.         else:
  116.             log.error('Device is busy or in an error state. Please check device and try again.')
  117.             sys.exit(1)
  118.         d.close()
  119.         log.info('')
  120.         log.notice('If an error occured, or the test page failed to print, refer to the HPLIP website')
  121.         log.notice('at: http://hplip.sourceforge.net for troubleshooting and support.')
  122.         log.info('')
  123. except KeyboardInterrupt:
  124.     log.error('User exit')
  125.  
  126. log.info('')
  127. log.info('Done.')
  128.